package server;

import com.sun.net.httpserver.*;

import java.net.InetSocketAddress;
import java.util.HashMap;

import server.handler.*;
import server.util.AuthorizationUtil;
import server.util.Base64Util;
import server.util.SessionUtil;



public class Server {

    public static void fuck() throws Exception{
        //throw new Exception("999999");
    }

    public static void main(String[] args) throws Exception {
        //Set login session
        //Handler.insertSession("cc175b9c0f1b6a831c399e269772661", "a");
        //create the http server to port 8080
        HttpServer server = HttpServer.create(new InetSocketAddress(8080),0);
        // Authorization login
        server.createContext("/registration", new RegistrationHandler());
        server.createContext("/login", new LoginHandler()).setAuthenticator(new AuthorizationUtil("login"));
        server.createContext("/coordinates", new CoordinateHandler()).setAuthenticator(new AuthorizationUtil("coordinates"));
        server.createContext("/query", new QueryHandler()).setAuthenticator(new AuthorizationUtil("query"));
        server.createContext("/comment", new CommentHandler()).setAuthenticator(new AuthorizationUtil("comment"));
        server.createContext("/logout", new LogoutHandler()).setAuthenticator(new AuthorizationUtil("logout"));
        server.setExecutor(null);
        server.start();
        //create the https server to port 8081
        HttpsServer servers = new HttpsServer(8081, System.getProperty("user.dir") + "/src/main/resources/server.jks", "123456");

        servers.createContext("/registration", new RegistrationHandler());
        servers.createContext("/login", new LoginHandler()).setAuthenticator(new AuthorizationUtil("login"));
        servers.createContext("/coordinates", new CoordinateHandler()).setAuthenticator(new AuthorizationUtil("coordinates"));
        servers.createContext("/query", new QueryHandler()).setAuthenticator(new AuthorizationUtil("query"));
        servers.createContext("/comment", new CommentHandler()).setAuthenticator(new AuthorizationUtil("comment"));
        servers.createContext("/logout", new LogoutHandler()).setAuthenticator(new AuthorizationUtil("logout"));
        servers.setExecutor(null);
        servers.start();
    }
}
